<template>
	<div style="width: 460px;display: inline-block;">
		<el-upload class="upload-demo" :action="apiurl+'admin/upload_file'" :on-success="UpSuccess" :on-remove="handleRemove"
			:on-preview="XiaZai" :file-list="fileList" :headers="picheaders"
			:accept="ispdf==1?'application/pdf':'application/pdf,application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.wordprocessingml.document'" :limit="1">
			<el-button size="small" type="primary">点击上传</el-button>

			<div slot="tip" class="el-upload__tip">只能上传pdf文件且只能上传一个附件</div>
		</el-upload>
	</div>
</template>
<script>
	export default {
		name: 'PicUp',
		props: {
			myList: Array,
			ispdf: {
				type: Number,
				default: 0,
			},
			num: {
				type: Number,
				default: 0,
			},
		},
		data() {
			return {
				pic: this.myIcon,
				text: this.myText,
				picheaders: {},
				apiurl: '/api/',
				fileList: this.myList,
				arr: [0, 1, 2, 3, 4, 5],
			}
		},
		created() {
			var that = this;
			let token = that.common.GetStorage('token');
			that.picheaders = {
				'X-Requested-With': 'XMLHttpRequest',
				'Authorization': 'Bearer ' + token,
			}
			// that.apiurl = that.common.CommLink();
		},
		methods: {
			XiaZai: function(e) {
				console.log(e.url);
				window.open('//' + e.url);
			},
			UpSuccess: function(e, file) {
				var that = this;
				var _arr = {
					name: file.name,
					url: file.response.fullurl,
				}
				console.log(_arr);
				that.fileList = that.fileList.concat(_arr);
				this.$emit('JoinFile', that.fileList, that.num);
			},
			handleRemove(file, fileList) {
				var that = this;
				console.log(file.name);
				var _arr1 = this.fileList;
				var _i = -1;
				_arr1.forEach(function(item, index) {
					if (item.name == file.name) {
						_i = index;
					}
				});
				console.log(_i)
				_arr1.splice(_i, 1);
				that.fileList = _arr1;
				this.$emit('JoinFile', that.fileList);
			},


			aa: function() {
				var _arr1 = this.arr;
				_arr1.splice(0, 1);
				console.log(this.arr);
			}
		}
	}
</script>